// CatAddin.h : Declaration of the CCatAddin

#ifndef __CATADDIN_H_
#define __CATADDIN_H_

#include "resource.h"       // main symbols

extern _ATL_FUNC_INFO DocumentOpenInfo;
extern _ATL_FUNC_INFO QuitInfo;
/////////////////////////////////////////////////////////////////////////////
// CCatAddin
class ATL_NO_VTABLE CCatAddin : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CCatAddin, &CLSID_CatAddin>,
	public IDispatchImpl<ICatAddin, &IID_ICatAddin, &LIBID_CATPARTNERLib>,
	public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
	public IDispEventSimpleImpl<1,CCatAddin,     
         &__uuidof(MSWORD::ApplicationEvents2)>
{
public:
	CCatAddin()
	{
		CreateMutex(NULL, FALSE, APPMUTEX);
		m_pInnerUnk = NULL;
		m_tmeplatefile = NULL;
	}
DECLARE_GET_CONTROLLING_UNKNOWN() 
DECLARE_REGISTRY_RESOURCEID(IDR_CATADDIN)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CCatAddin)
	COM_INTERFACE_ENTRY(ICatAddin)
//DEL 	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY2(IDispatch, ICatAddin)
	COM_INTERFACE_ENTRY(_IDTExtensibility2)
	COM_INTERFACE_ENTRY_AGGREGATE( IID_ICatAddin, m_pInnerUnk)
END_COM_MAP()

// ICatAddin
public:
// _IDTExtensibility2
	typedef IDispEventSimpleImpl<1,CCatAddin,     
         &__uuidof(MSWORD::ApplicationEvents2)> AppEvents;
	STDMETHOD(OnConnection)(IDispatch * Application, ext_ConnectMode ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom);
	STDMETHOD(OnDisconnection)(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom);
	STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom);
	STDMETHOD(OnAddInsUpdate)(SAFEARRAY * * custom)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(OnBeginShutdown)(SAFEARRAY * * custom)
	{
		return E_NOTIMPL;
	}

	void __stdcall DocumentOpen(IDispatchPtr ptr);
	void __stdcall Quit();

	BEGIN_SINK_MAP(CCatAddin)
		SINK_ENTRY_INFO(1,__uuidof(MSWORD::ApplicationEvents2),4,DocumentOpen,&DocumentOpenInfo)
		SINK_ENTRY_INFO(1,__uuidof(MSWORD::ApplicationEvents2),2,Quit, &QuitInfo)
	END_SINK_MAP()
private :
	LPUNKNOWN m_pInnerUnk;
	CComPtr<MSWORD::_Application> m_spApp;
	LPCTSTR m_pPath;
	Template* m_tmeplatefile ;
	CComBSTR m_ShortCut[10];
	HWND m_hWnd;
	CComBSTR m_Error, m_FileVer;
private:
	LPTSTR GetCurrentPath();
	LPCTSTR GetCurrentPathFile( LPCTSTR exe);
};

#endif //__CATADDIN_H_
